package com.fy.fyspace.controller;

import com.fy.fyspace.common.annotation.GlobalInterceptor;
import com.fy.fyspace.common.result.R;
import com.fy.fyspace.model.vo.user.UserSessionVO;
import com.fy.fyspace.service.LikePictureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 图片点赞表 前端控制器
 * </p>
 *
 * @author fwq
 * @since 2025-06-26
 */
@Api(tags = "图片点赞模块")
@RestController
@RequestMapping("/likepicture")
public class LikePictureController {

    @Resource
    private LikePictureService likePictureService;

    /**
     * 批量点赞图片
     * @param picIds 图片ID列表，逗号分隔
     * @return 结果
     */
    @ApiOperation(value = "批量点赞图片", notes = "批量点赞图片，picIds为逗号分隔的图片ID字符串")
    @PostMapping("/like/batch")
    @GlobalInterceptor
    public R batchLikePictures(
            @ApiParam(value = "图片ID列表，逗号分隔", required = true)
            @RequestParam String picIds) {
        return likePictureService.batchLikePictures(picIds);
    }

    /**
     * 批量取消点赞
     * @param picIds
     * @return
     */
    @ApiOperation(value = "批量取消点赞", notes = "批量取消点赞，picIds为逗号分隔的图片ID字符串")
    @PostMapping("/cancel/batch")
    @GlobalInterceptor
    public R batchCancelLikePictures(
            @ApiParam(value = "图片ID列表，逗号分隔", required = true)
            @RequestParam String picIds) {
        return likePictureService.batchCancelLikePictures(picIds);
    }

    /**
     * 获取我的点赞图片列表
     * @param pageNo
     * @param pageSize
     * @param searchText
     * @param color
     * @param session
     * @return
     */
    @ApiOperation(value = "获取我的点赞图片列表", notes = "分页获取当前用户点赞的图片列表，可按颜色筛选，无缓存")
    @GetMapping("/my-like/list")
    @GlobalInterceptor
    public R getMyLikePictureList(@RequestParam(required = false) Integer pageNo,
                                       @RequestParam(required = false) Integer pageSize,
                                       @RequestParam(required = false) String searchText,
                                       @RequestParam(required = false) String color,
                                       HttpSession session) {
        UserSessionVO userSessionVO = (UserSessionVO) session.getAttribute(com.fy.fyspace.constant.KeysConstant.LOGIN_SESSION_KEY);
        return likePictureService.getMyLikePictureList(userSessionVO.getId(), pageNo, pageSize, searchText, color);
    }
}
